<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="http://www.petercorke.com/RVC/common/toolboxhelp.css">
    <title>M-File Help: Polygon</title>
  </head>
  <body>
  <table border="0" cellspacing="0" width="100%">
    <tr class="subheader">
      <td class="headertitle">M-File Help: Polygon</td>
      <td class="subheader-left"><a href="matlab:open Polygon">View code for Polygon</a></td>
    </tr>
  </table>
<h1>Polygon</h1><p><span class="helptopic">Polygon class</span></p><p>
A general class for manipulating polygons and vectors of polygons.

</p>
<h2>Methods</h2>
<table class="list">
  <tr><td style="white-space: nowrap;" class="col1"> plot</td> <td>Plot polygon</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> area</td> <td>Area of polygon</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> moments</td> <td>Moments of polygon</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> centroid</td> <td>Centroid of polygon</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> perimeter</td> <td>Perimter of polygon</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> transform</td> <td>Transform polygon</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> inside</td> <td>Test if points are inside polygon</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> intersection</td> <td>Intersection of two polygons</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> difference</td> <td>Difference of two polygons</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> union</td> <td>Union of two polygons</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> xor</td> <td>Exclusive or of two polygons</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> display</td> <td>print the polygon in human readable form</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> char</td> <td>convert the polgyon to human readable string</td></tr>
</table>
<h2>Properties</h2>
<table class="list">
  <tr><td style="white-space: nowrap;" class="col1"> vertices</td> <td>List of polygon vertices, one per column</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> extent</td> <td>Bounding box [minx maxx; miny maxy]</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> n </td> <td>Number of vertices</td></tr>
</table>
<h2>Notes</h2>
<ul>
  <li>This is reference class object</li>
  <li>Polygon objects can be used in vectors and arrays</li>
</ul>
<h2>Acknowledgement</h2>
<p>
The methods: inside, intersection, difference, union, and xor are based on code
written by:

</p>
<p>
Kirill K. Pankratov, kirill@plume.mit.edu,
http://puddle.mit.edu/~glenn/kirill/saga.html

</p>
<p>
and require a licence.  However the author does not respond to email regarding
the licence, so use with care, and modify with acknowledgement.

</p>
<hr>
<a name="Polygon"><h1>Polygon.Polygon</h1></a>
<p><span class="helptopic">Polygon class constructor</span></p><p>
<strong>p</strong> = <span style="color:red">Polygon</span>(<strong>v</strong>) is a polygon with vertices given by <strong>v</strong>, one column per
vertex.

</p>
<p>
<strong>p</strong> = <span style="color:red">Polygon</span>(<strong>C</strong>, <strong>wh</strong>) is a rectangle centred at <strong>C</strong> with dimensions
<strong>wh</strong>=[WIDTH, HEIGHT].

</p>
<hr>
<a name="area"><h1>Polygon.area</h1></a>
<p><span class="helptopic">Area of polygon</span></p><p>
<strong>a</strong> = P.<span style="color:red">area</span>() is the <span style="color:red">area</span> of the polygon.

</p>
<h2>See also</h2>
<p>
<a href="Polygon.moments.html">Polygon.moments</a></p>
<hr>
<a name="centroid"><h1>Polygon.centroid</h1></a>
<p><span class="helptopic">Centroid of polygon</span></p><p>
<strong>x</strong> = P.<span style="color:red">centroid</span>() is the <span style="color:red">centroid</span> of the polygon.

</p>
<h2>See also</h2>
<p>
<a href="Polygon.moments.html">Polygon.moments</a></p>
<hr>
<a name="char"><h1>Polygon.char</h1></a>
<p><span class="helptopic">String representation</span></p><p>
<strong>s</strong> = P.<span style="color:red">char</span>() is a compact representation of the polgyon in human
readable form.

</p>
<hr>
<a name="difference"><h1>Polygon.difference</h1></a>
<p><span class="helptopic">Difference of polygons</span></p><p>
<strong>d</strong> = P.<span style="color:red">difference</span>(<strong>q</strong>) is polygon P minus polygon <strong>q</strong>.

</p>
<h2>Notes</h2>
<ul>
  <li>If polygons P and Q are not intersecting, returns
coordinates of P.</li>
  <li>If the result D is not simply connected or consists of
several polygons, resulting vertex list will contain NaNs.</li>
</ul>
<hr>
<a name="display"><h1>Polygon.display</h1></a>
<p><span class="helptopic">Display polygon</span></p><p>
P.<span style="color:red">display</span>() displays the polygon in a compact human readable form.

</p>
<h2>See also</h2>
<p>
<a href="Polygon.char.html">Polygon.char</a></p>
<hr>
<a name="inside"><h1>Polygon.inside</h1></a>
<p><span class="helptopic">Test if points are inside polygon</span></p><p>
<strong>in</strong> = <strong>p</strong>.<span style="color:red">inside</span>(<strong>p</strong>) tests if points given by columns of <strong>p</strong> (2xN) are <span style="color:red">inside</span>
the polygon.  The corresponding elements of <strong>in</strong> (1xN) are either true or
false.

</p>
<hr>
<a name="intersect"><h1>Polygon.intersect</h1></a>
<p><span class="helptopic">Intersection of polygon with list of polygons</span></p><p>
<strong>i</strong> = P.<span style="color:red">intersect</span>(<strong>plist</strong>) indicates whether or not the <span style="color:red">Polygon</span> P
intersects with

</p>
<p>
<span style="color:red">i</span>(<strong>j</strong>) = 1 if p intersects polylist(<strong>j</strong>), else 0.

</p>
<hr>
<a name="intersect_line"><h1>Polygon.intersect_line</h1></a>
<p><span class="helptopic">Intersection of polygon and line segment</span></p><p>
<strong>i</strong> = P.<span style="color:red">intersect_line</span>(<strong>L</strong>) is the intersection points of a polygon P with
the line segment <strong>L</strong>=[x1 x2; y1 y2].  <strong>i</strong> (2xN) has one column per
intersection, each column is [x y]'.

</p>
<hr>
<a name="intersection"><h1>Polygon.intersection</h1></a>
<p><span class="helptopic">Intersection of polygons</span></p><p>
<strong>i</strong> = P.<span style="color:red">intersection</span>(<strong>q</strong>) is a <span style="color:red">Polygon</span> representing the
<span style="color:red">intersection</span> of polygons P and <strong>q</strong>.

</p>
<h2>Notes</h2>
<ul>
  <li>If these polygons are not intersecting, returns empty polygon.</li>
  <li>If intersection consist of several disjoint polygons
(for non-convex P or Q) then vertices of I is the concatenation
of the vertices of these polygons.</li>
</ul>
<hr>
<a name="moments"><h1>Polygon.moments</h1></a>
<p><span class="helptopic">Moments of polygon</span></p><p>
<strong>a</strong> = P.<span style="color:red">moments</span>(<strong>p</strong>, <strong>q</strong>) is the pq'th moment of the polygon.

</p>
<h2>See also</h2>
<p>
<a href="Polygon.area.html">Polygon.area</a>, <a href="Polygon.centroid.html">Polygon.centroid</a>, <a href="mpq_poly.html">mpq_poly</a></p>
<hr>
<a name="perimeter"><h1>Polygon.perimeter</h1></a>
<p><span class="helptopic">Perimeter of polygon</span></p><p>
<strong>L</strong> = P.<span style="color:red">perimeter</span>() is the <span style="color:red">perimeter</span> of the polygon.

</p>
<hr>
<a name="plot"><h1>Polygon.plot</h1></a>
<p><span class="helptopic">Draw polygon</span></p><p>
P.<span style="color:red">plot</span>() draws the polygon P in the current <span style="color:red">plot</span>.

</p>
<p>
P.<span style="color:red">plot</span>(<strong>ls</strong>) as above but pass the arguments <strong>ls</strong> to <span style="color:red">plot</span>.

</p>
<h2>Notes</h2>
<ul>
  <li>The polygon is added to the current plot.</li>
</ul>
<hr>
<a name="transform"><h1>Polygon.transform</h1></a>
<p><span class="helptopic">Transform polygon vertices</span></p><p>
<strong>p2</strong> = P.<span style="color:red">transform</span>(<strong>T</strong>) is a new <span style="color:red">Polygon</span> object whose vertices have
been transformed by the SE(2) homgoeneous transformation <strong>T</strong> (3x3).

</p>
<hr>
<a name="union"><h1>Polygon.union</h1></a>
<p><span class="helptopic">Union of polygons</span></p><p>
<strong>i</strong> = P.<span style="color:red">union</span>(<strong>q</strong>) is a polygon representing the
<span style="color:red">union</span> of polygons P and <strong>q</strong>.

</p>
<h2>Notes</h2>
<ul>
  <li>If these polygons are not intersecting, returns a polygon with
vertices of both polygons separated by NaNs.</li>
  <li>If the result P is not simply connected (such as a polygon
with a "hole") the resulting contour consist of counter-
clockwise "outer boundary" and one or more clock-wise
"inner boundaries" around "holes".</li>
</ul>
<hr>
<a name="xor"><h1>Polygon.xor</h1></a>
<p><span class="helptopic">Exclusive or of polygons</span></p><p>
<strong>i</strong> = P.<span style="color:red">union</span>(<strong>q</strong>) is a polygon representing the
exclusive-or of polygons P and <strong>q</strong>.

</p>
<h2>Notes</h2>
<ul>
  <li>If these polygons are not intersecting, returns a polygon with
vertices of both polygons separated by NaNs.</li>
  <li>If the result P is not simply connected (such as a polygon
with a "hole") the resulting contour consist of counter-
clockwise "outer boundary" and one or more clock-wise
"inner boundaries" around "holes".</li>
</ul>
<hr>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr class="subheader" valign="top"><td>&nbsp;</td></tr></table>
<p class="copy">&copy; 1990-2014 Peter Corke.</p>
</body></html>